#define _GNU_SOURCE // 如是不声明gettid()不识别报错
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

void *first_thread (void *argv)
{
    printf("线程1(%d)开始执行，准备休息1秒 \n", gettid());
    sleep(1);
    printf("线程1(%d)醒来了 \n", gettid());
}

void *second_thread (void *argv)
{
    printf("线程2(%d)开始执行，准备休息1秒 \n", gettid());
    sleep(1);
    printf("线程2(%d)醒来了 \n", gettid());
}

int main ()
{
    printf("main线程(%d)执行 \n", gettid());

    pthread_t thread_f;
    pthread_t thread_s;

    pthread_create(&thread_f, NULL, first_thread, NULL);
    pthread_create(&thread_s, NULL, second_thread, NULL);

    printf("main线程执行，线程1的标识：%ld, 线程2的标识：%ld \n", thread_f, thread_s);

    pthread_join(thread_f, NULL);
    pthread_join(thread_s, NULL);

    printf("main线程执行完成");

    return 0;
}